package com.eduction.modules.system.dao;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.eduction.common.dbutil.DbHelper;
import com.eduction.modules.system.entity.CityEntity;
import com.eduction.modules.system.entity.School;
import com.eduction.modules.system.entity.SchoolType;
import com.eduction.modules.system.entity.SysMenuEntity;
import com.hazelcast.util.MD5Util;

@Repository
public class SystemDao {
	@Autowired	
	private DbHelper dbHelper;
	public List<SysMenuEntity> getMenu(String fid) throws SQLException{
		String sql = "select * from t_sys_menu where p_fid = ? ";
		return dbHelper.getBeanList(sql, SysMenuEntity.class, fid);
	}
	
	public List<SchoolType> getSchoolType(int status) throws SQLException {
		String sql = "select * from t_school_type where p_status=? ";
		return dbHelper.getBeanList(sql, SchoolType.class, status);
	}
	public SchoolType getSchoolTypeById(String id) throws SQLException {
		String sql = "select * from t_school_type where p_id=? limit 1";
		return dbHelper.getBean(sql, SchoolType.class, id);
	}
	/**
	 * 根据学校类型查学校
	 * @param tid
	 * @return   
	 * @throws SQLException
	 */
	public List<School> getSchool(String tid) throws SQLException{
		String sql = "select * from t_school where p_type_id = ?";
		return dbHelper.getBeanList(sql, School.class, tid);
	}
	/**
	 * 
	 * @param tid
	 * @return
	 * @throws SQLException
	 */
	public School getSchool(String id,String pass) throws SQLException{
		String sql = "select * from t_school where p_id = ? and p_password=? limit 1";
		return dbHelper.getBean(sql, School.class, new Object[]{id,MD5Util.toMD5String(pass)});
	}
	
	public CityEntity getCityById(String id) throws SQLException{
		String sql = "select * from t_sys_city where p_id = ?";
		CityEntity cityEntity = dbHelper.getBean(sql, CityEntity.class, id);
		return cityEntity==null?new CityEntity():cityEntity;
	}
}
